package com.warm.system.controller.monitor;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.warm.core.domain.AjaxResult;
import com.warm.core.page.BaseController;
import com.warm.core.page.TableDataInfo;
import com.warm.excel.poi.utils.ExcelUtil;
import com.warm.log.annotation.Log;
import com.warm.log.enums.BusinessType;
import com.warm.select.api.orm.domain.sys.SysOperLog;
import com.warm.system.service.ISysOperLogService;
import org.noear.solon.annotation.*;
import org.noear.solon.core.handle.Context;
import org.noear.solon.validation.annotation.Valid;

import java.util.List;

/**
 * 操作日志记录
 *
 * @author warm
 */
@Valid
@Controller
@Mapping("/monitor/operlog")
public class SysOperlogController extends BaseController {
    @Inject
    private ISysOperLogService operLogService;

    @SaCheckPermission("monitor:operlog:list")
    @Get
    @Mapping("/list")
    public TableDataInfo<SysOperLog> list(SysOperLog operLog) {
        return operLogService.selectOperLogPage(operLog);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @SaCheckPermission("monitor:operlog:export")
    @Post
    @Mapping("/export")
    public void export(Context ctx, SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<>(SysOperLog.class);
        util.exportExcel(ctx, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @SaCheckPermission("monitor:operlog:remove")
    @Delete
    @Mapping("/{operIds}")
    public AjaxResult remove(Long[] operIds) {
        return toAjax(operLogService.deleteOperLogByIds(operIds));
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @SaCheckPermission("monitor:operlog:remove")
    @Delete
    @Mapping("/clean")
    public AjaxResult clean() {
        operLogService.cleanOperLog();
        return success();
    }
}
